/*
 * @Author: 89-83-77
 * @Description: 请填写当前文件简介
 * @Date: 2025-03-27 16:57:22
 * @LastEditTime: 2025-03-27 16:57:27
 * @FilePath: \fz-yzt-webd:\work\client\server\app.js
 */
const express = require("express");
const cors = require("cors");
const app = express();

// 中间件
app.use(cors());
app.use(express.json());

// 示例路由
app.get("/api/data", (req, res) => {
  res.json({
    code: 200,
    data: [
      /* 模拟数据 */
    ],
  });
});

// 添加登录接口
app.post("/api/login", (req, res) => {
  const { username, password } = req.body;
  if (username === "admin" && password === "123456") {
    res.json({
      code: 200,
      data: {
        token: "demo-token",
        userInfo: {
          username: "admin",
          role: "admin",
        },
      },
    });
  } else {
    res.status(401).json({ code: 401, message: "认证失败" });
  }
});

// 用户管理接口
app.get("/api/users", (req, res) => {
  res.json({
    code: 200,
    data: {
      list: [
        { id: 1, username: "admin", role: "管理员" },
        { id: 2, username: "user1", role: "普通用户" },
      ],
      total: 2,
    },
  });
});

// 启动服务
const PORT = 3000;
app.listen(PORT, () => {
  console.log(`Server running at http://localhost:${PORT}`);
});
